package com.j180.dao.comment;

import com.github.pagehelper.PageInfo;
import com.j180.bean.Comment;
import org.apache.ibatis.annotations.*;


import java.util.List;

public interface ICommentDao {

    /**
     * 查询所有评论信息
     * @return 查询结果集
     */
    @Select(" SELECT\n" +
            "            com.c_id,\n" +
            "            com.c_time,\n" +
            "            com.c_score,\n" +
            "            com.c_content,\n" +
            "            com.c_pic,\n" +
            "            com.c_type,\n" +
            "            sto.st_id,\n" +
            "            sto.st_name,\n" +
            "            sto.st_licenseNum,\n" +
            "            sto.st_licensePic,\n" +
            "            sto.st_address,\n" +
            "            sto.st_location,\n" +
            "            sto.st_city,\n" +
            "            sto.st_corporation,\n" +
            "            sto.st_telNum,\n" +
            "            sto.st_photo,\n" +
            "            sto.st_feature,\n" +
            "            sto.st_vipLevel,\n" +
            "            sto.st_commissionRate,\n" +
            "            sto.st_clerkAttri\n" +
            "        FROM\n" +
            "            t_comment AS com\n" +
            "                LEFT JOIN t_store AS sto ON com.c_st_id = sto.st_id")
    @ResultMap("commentResult.commentMap")
    public List<Comment> getAllComment();


    /**
     * 根据评论id查询单条评论详细信息
     * @param id 评论id
     * @return 查询结果
     */
    @Select(" SELECT\n" +
            "            com.c_id,\n" +
            "            com.c_time,\n" +
            "            com.c_score,\n" +
            "            com.c_content,\n" +
            "            com.c_pic,\n" +
            "            com.c_type,\n" +
            "            sto.st_id,\n" +
            "            sto.st_name,\n" +
            "            sto.st_licenseNum,\n" +
            "            sto.st_licensePic,\n" +
            "            sto.st_address,\n" +
            "            sto.st_location,\n" +
            "            sto.st_city,\n" +
            "            sto.st_corporation,\n" +
            "            sto.st_telNum,\n" +
            "            sto.st_photo,\n" +
            "            sto.st_feature,\n" +
            "            sto.st_vipLevel,\n" +
            "            sto.st_commissionRate,\n" +
            "            sto.st_clerkAttri\n" +
            "        FROM\n" +
            "            t_comment AS com\n" +
            "                LEFT JOIN t_store AS sto ON com.c_st_id = sto.st_id where c_id =#{id}")
    @ResultMap("commentResult.commentMap")
    public Comment getDetailCommentById(@Param("id") int id);


    /**
     * 添加一条评论
     * @param comment 评论实体类
     */
    @Insert("insert into t_comment values(null,#{store.id},#{time},#{score},#{content},#{pic},#{type})")
    public int addComment(Comment comment);


    /**
     * 根据评论id删除一条评论
     * @param id 评论id
     */
    @Delete("delete from t_comment where c_id=#{id}")
    public int delComment(@Param("id")int id);

    /**
     * 根据评论ID修改一条评论
     * @param comment 评论实体类
     */
    @Update("update t_comment set c_st_id=#{store.id},c_time=#{time},c_score=#{score},c_content=#{content},c_pic=#{pic},c_type=#{type} where c_id=#{id}")
    public int editComment(Comment comment);

}
